home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSWorld.as < prev    next >
Text File  |  2006-11-29  |  9KB  |  312 lines

  1. class SSWorld extends GDK.World
  2. {
  3.    static var viewportClass = GameViewport;
  4.    var useDefaultCamera = false;
  5.    var updateID = 0;
  6.    var time = 0;
  7.    var levelLeft = 0;
  8.    var levelTop = 0;
  9.    var levelRight = 0;
  10.    var levelBottom = 0;
  11.    var leftSector = 0;
  12.    var rightSector = 0;
  13.    var topSector = 0;
  14.    var bottomSector = 0;
  15.    var sectorsWide = 0;
  16.    var sectorsTotal = 0;
  17.    var soundsCreated = 0;
  18.    var normalVolume = 100;
  19.    var muteVolume = 0;
  20.    function SSWorld(name, viewport)
  21.    {
  22.       super();
  23.       this.sectors = {};
  24.       this.players = [];
  25.       if(name)
  26.       {
  27.          this.name = name;
  28.       }
  29.       this.viewport = new SSWorld.viewportClass();
  30.       this.backgrounds = new GDK.Collection();
  31.       this.collections = {};
  32.    }
  33.    function addToCollection(name, obj)
  34.    {
  35.       var _loc3_ = this.collections[name];
  36.       if(!_loc3_)
  37.       {
  38.          var _loc0_ = null;
  39.          _loc3_ = this.collections[name] = [obj];
  40.       }
  41.       else
  42.       {
  43.          var _loc2_ = _loc3_.length;
  44.          while((_loc2_ = _loc2_ - 1) > -1)
  45.          {
  46.             if(_loc3_[_loc2_] == obj)
  47.             {
  48.                return undefined;
  49.             }
  50.          }
  51.          _loc3_.push(obj);
  52.       }
  53.    }
  54.    function removeFromCollection(name, obj)
  55.    {
  56.       var _loc3_ = undefined;
  57.       var _loc2_ = _loc3_ = this.collections[name].length;
  58.       while((_loc2_ = _loc2_ - 1) > -1)
  59.       {
  60.          if(_loc3_[_loc2_] == obj)
  61.          {
  62.             _loc3_.splice(_loc2_,1);
  63.          }
  64.       }
  65.    }
  66.    function addBackground(bg)
  67.    {
  68.       bg.world = bg.parent = this;
  69.       bg.displayNode = this.target;
  70.       bg.uniqueID = ++this.objectsAdded;
  71.       this.backgrounds.addMember(bg);
  72.    }
  73.    function update(elapsed)
  74.    {
  75.       this.tick = Math.floor(this.time) != Math.floor(this.time += elapsed);
  76.       var _loc2_ = this.players.length;
  77.       while((_loc2_ = _loc2_ - 1) > -1)
  78.       {
  79.          this.players[_loc2_].update(elapsed);
  80.       }
  81.       this.sendEvent("update",elapsed);
  82.       this.updateViewport(elapsed);
  83.       if(this.viewport.sectorChanged)
  84.       {
  85.          this.cleanScene();
  86.       }
  87.       this.render(elapsed);
  88.    }
  89.    function cleanScene()
  90.    {
  91.       var _loc6_ = [];
  92.       this.viewport.sectorChanged = false;
  93.       var _loc7_ = this.sectorsWide;
  94.       var _loc3_ = undefined;
  95.       var _loc10_ = this.sectorsTotal;
  96.       while((_loc10_ = _loc10_ - 1) > -1)
  97.       {
  98.          if(_loc3_ = this.sectors[this.leftSector + _loc10_ % _loc7_][this.topSector + Math.floor(_loc10_ / _loc7_)])
  99.          {
  100.             _loc3_._s = -1;
  101.             _loc6_.push(_loc3_);
  102.          }
  103.       }
  104.       var _loc0_ = null;
  105.       var _loc0_ = null;
  106.       _loc10_ = this.sectorsTotal = (_loc7_ = this.sectorsWide = (this.rightSector = this.viewport.rightSector) - (this.leftSector = this.viewport.leftSector)) * ((this.bottomSector = this.viewport.bottomSector) - (this.topSector = this.viewport.topSector));
  107.       while((_loc10_ = _loc10_ - 1) > -1)
  108.       {
  109.          if(_loc3_ = this.sectors[this.leftSector + _loc10_ % _loc7_][this.topSector + Math.floor(_loc10_ / _loc7_)])
  110.          {
  111.             if(!_loc3_._s)
  112.             {
  113.                _loc3_._s = 1;
  114.                _loc6_.push(_loc3_);
  115.             }
  116.             else
  117.             {
  118.                _loc3_._s = 0;
  119.             }
  120.          }
  121.       }
  122.       _loc10_ = _loc6_.length;
  123.       var _loc9_ = [];
  124.       var _loc4_ = undefined;
  125.       var _loc2_ = undefined;
  126.       var _loc8_ = undefined;
  127.       var _loc5_ = undefined;
  128.       while((_loc10_ = _loc10_ - 1) > -1)
  129.       {
  130.          _loc5_ = _loc8_ = _loc6_[_loc10_].length;
  131.          _loc4_ = _loc8_._s;
  132.          while((_loc5_ = _loc5_ - 1) > -1)
  133.          {
  134.             if(_loc2_ = _loc8_[_loc5_]._s == null)
  135.             {
  136.                _loc2_._s = _loc4_;
  137.                _loc9_.push(_loc2_);
  138.             }
  139.             else if(_loc4_ > _loc2_._s)
  140.             {
  141.                _loc2_._s = _loc4_;
  142.             }
  143.          }
  144.          delete _loc6_[_loc10_]._s;
  145.       }
  146.       _loc10_ = _loc9_.length;
  147.       while((_loc10_ = _loc10_ - 1) > -1)
  148.       {
  149.          _loc2_ = _loc9_[_loc10_];
  150.          if(_loc2_._s < 0)
  151.          {
  152.             _loc2_.removeFromScene();
  153.          }
  154.          else if(_loc2_._s > 0)
  155.          {
  156.             _loc2_.addToScene();
  157.          }
  158.          delete _loc2_._s;
  159.       }
  160.    }
  161.    function render(elapsed)
  162.    {
  163.       if(!this.displayQueue.length)
  164.       {
  165.          return undefined;
  166.       }
  167.       if(this.viewport.changed)
  168.       {
  169.          this.target._x = Math.floor(- this.viewport.x);
  170.          this.target._y = Math.floor(- this.viewport.y);
  171.          var _loc2_ = this.backgrounds.length;
  172.          while((_loc2_ = _loc2_ - 1) > -1)
  173.          {
  174.             this.backgrounds[_loc2_].setDisplay(this.viewport);
  175.          }
  176.       }
  177.       var _loc3_ = this.viewport.wTan * 1 / this.viewport.focusDepth;
  178.       _loc2_ = this.displayQueue.length;
  179.       while((_loc2_ = _loc2_ - 1) > -1)
  180.       {
  181.          this.displayQueue[_loc2_].setDisplay(this.viewport,elapsed,_loc3_);
  182.          delete this.displayQueue[_loc2_].queueForDisplay;
  183.       }
  184.       this.displayQueue = [];
  185.       this.viewport.changed = false;
  186.       updateAfterEvent();
  187.    }
  188.    function getSectors(l, t, r, b)
  189.    {
  190.       var _loc6_ = this.sectors;
  191.       var _loc3_ = undefined;
  192.       var _loc2_ = (_loc3_ = r - l + 1) * (b - t + 1);
  193.       var _loc4_ = undefined;
  194.       r = [];
  195.       while((_loc2_ = _loc2_ - 1) > -1)
  196.       {
  197.          if(_loc4_ = _loc6_[l + _loc2_ % _loc3_][t + Math.floor(_loc2_ / _loc3_)])
  198.          {
  199.             r.push(_loc4_);
  200.          }
  201.       }
  202.       return r;
  203.    }
  204.    function getObjectsInSectors(l, t, r, b)
  205.    {
  206.       var _loc6_ = this.sectors;
  207.       var _loc4_ = undefined;
  208.       var _loc2_ = (_loc4_ = r - l + 1) * (b - t + 1);
  209.       var _loc5_ = undefined;
  210.       var _loc3_ = [];
  211.       while((_loc2_ = _loc2_ - 1) > -1)
  212.       {
  213.          if(_loc5_ = _loc6_[l + _loc2_ % _loc4_][t + Math.floor(_loc2_ / _loc4_)])
  214.          {
  215.             _loc3_ = _loc3_.concat(_loc5_);
  216.          }
  217.       }
  218.       return _loc3_;
  219.    }
  220.    function updateViewport(elapsed)
  221.    {
  222.       this.viewport.update(elapsed);
  223.    }
  224.    function onAddToScene()
  225.    {
  226.       this.target._visible = true;
  227.       this.viewport.screenWidth = this.engine.width;
  228.       this.viewport.screenHeight = this.engine.height;
  229.       this.viewport.world = this;
  230.       this.viewport.onAddToWorld();
  231.       var _loc2_ = this.backgrounds.length;
  232.       while((_loc2_ = _loc2_ - 1) > -1)
  233.       {
  234.          this.backgrounds[_loc2_].addDisplay();
  235.          this.backgrounds[_loc2_].setDisplay(this.viewport);
  236.       }
  237.       this.onSSAddToScene();
  238.    }
  239.    function onAddDisplay()
  240.    {
  241.       this.soundContainer = this.target.createEmptyMovieClip("SoundContainer",-1200);
  242.       this.soundObject = new Sound(this.soundContainer);
  243.       this.initSound();
  244.    }
  245.    function removeFromScene()
  246.    {
  247.       this.target._visible = false;
  248.       this.inScene = false;
  249.       for(var _loc2_ in this.soundContainer)
  250.       {
  251.          this.soundContainer[_loc2_].sound.stop();
  252.       }
  253.    }
  254.    function createSound(id, linkageID)
  255.    {
  256.       if(linkageID != null)
  257.       {
  258.          var _loc2_ = this.soundContainer.attachMovie(linkageID,id,++this.soundsCreated);
  259.       }
  260.       else
  261.       {
  262.          _loc2_ = this.soundContainer.createEmptyMovieClip(id,++this.soundsCreated);
  263.       }
  264.       var _loc3_ = new Sound(_loc2_);
  265.       _loc2_.sound = _loc3_;
  266.       return _loc2_;
  267.    }
  268.    function muteSounds()
  269.    {
  270.       this.soundObject.setVolume(this.muteVolume);
  271.    }
  272.    function unmuteSounds()
  273.    {
  274.       this.soundObject.setVolume(this.normalVolume);
  275.    }
  276.    function deleteSound(id)
  277.    {
  278.       this.soundContainer[id].sound.stop();
  279.       this.soundContainer[id].removeMovieClip();
  280.    }
  281.    function playEventSound(id, name)
  282.    {
  283.       if(id.sound)
  284.       {
  285.          var _loc2_ = id;
  286.       }
  287.       else
  288.       {
  289.          _loc2_ = this.soundContainer[id];
  290.       }
  291.       _loc2_.gotoAndStop(name);
  292.       _loc2_.nextFrame();
  293.    }
  294.    function addPlayer(player)
  295.    {
  296.       this.players.push(player);
  297.    }
  298.    function removePlayer(player)
  299.    {
  300.       var _loc3_ = undefined;
  301.       var _loc2_ = _loc3_ = this.players.length;
  302.       while((_loc2_ = _loc2_ - 1) > -1)
  303.       {
  304.          if(_loc3_[_loc2_] == player)
  305.          {
  306.             _loc3_.splice(_loc2_,1);
  307.             break;
  308.          }
  309.       }
  310.    }
  311. }
  312.